from appium import webdriver
import time,logging


class Driver:
    __app__driver = None

    @classmethod
    def get_app_driver(cls):
        if cls.__app__driver == None:
            logging.info("开启服务")
            cls.desired_caps = {
                "platformName": "Android",
                "platformVersion": "",
                "deviceName": "aa",
                "appPackage": "com.yunmall.lc",
                "appActivity": "com.yunmall.ymctoc.ui.activity.MainActivity"
            }

            cls.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", cls.desired_caps)
            cls.__app__driver = cls.driver
        return cls.__app__driver

    @classmethod
    def quit_app_driver(cls):
        if cls.__app__driver is not None:
            logging.info("关闭服务")
            cls.__app__driver.quit()
            # print(cls.__app__driver)
            cls.__app__driver = None


if __name__ == '__main__':
    Driver.get_app_driver()

    time.sleep(3)
    Driver.get_app_driver()
    time.sleep(2)
    Driver.quit_app_driver()

